home *** CD-ROM | disk | FTP | other *** search
/ PC Player 2004 May / pc player 2004-05.iso / Demos / FarCry / Data1.cab / _DA9E6F47E28A4C41A2B811FCBCC16E54 < prev    next >
Encoding:
Text File  |  2004-01-06  |  6.1 KB  |  287 lines

  1. --
  2. -- control options menu page
  3. --
  4.  
  5.  
  6. UI.PageOptionsControl=
  7. {
  8.     KeyOrder=
  9.     {
  10.         MOVEMENT=
  11.         {
  12.             "MoveForward",
  13.             "MoveBackward",
  14.             "MoveLeft",
  15.             "MoveRight",
  16.             "Jump",
  17.             "Crouch",
  18.             "Prone",
  19.             "Walk",
  20.             "SprintRun",
  21.             "LeanLeft",
  22.             "LeanRight",
  23.         },
  24.         
  25.         MULTIPLAYER=
  26.         {
  27.             "Chat",
  28.             "TeamChat",
  29.             "ViewScoreboard",
  30.         },
  31.  
  32.         GAME=
  33.         {
  34.             "Use",
  35.             "HoldBreath",
  36.             "ToggleFlashlight",
  37.             "Binoculars",
  38.             "ThermalVision",
  39.             "TakeScreenshot",
  40.         },    
  41.  
  42.         COMBAT=
  43.         {        
  44.             "Fire",
  45.             "Reload",
  46.             "ToggleFiremode",
  47.             "NextWeapon",
  48.             "PrevWeapon",
  49.             "DropWeapon",
  50.             "CycleGrenade",
  51.             "ThrowGrenade",
  52.             "ToggleZoom",
  53.             "ZoomIn",
  54.             "ZoomOut",
  55.             "Slot1",
  56.             "Slot2",
  57.             "Slot3",
  58.             "Slot4",
  59.         },
  60.     },
  61.  
  62.     GUI=
  63.     {
  64.         sensitivitytext=
  65.         {
  66.             skin = UI.skins.Label,
  67.             left = 200, top = 415,
  68.             width = 142, height = 28,
  69.             
  70.             text=Localize("MouseSensitivity"),
  71.         },
  72.         
  73.         sensitivity=
  74.         {
  75.             skin = UI.skins.HScrollBar,
  76.             
  77.             left = 350, top = 419,
  78.             width = 200,
  79.             
  80.             tabstop = 2,
  81.  
  82.             OnChanged = function(Sender)
  83.                 Input:SetMouseSensitivity(Sender:GetValue()*50.0+5.0);
  84.             end,
  85.         },
  86.         
  87.         invertmousetext=
  88.         {
  89.             skin = UI.skins.Label,
  90.             
  91.             left = 590, top = 415,
  92.             width = 112,
  93.             
  94.             text=Localize("InvertMouse"),
  95.         },
  96.  
  97.         invertmouse=
  98.         {
  99.             skin = UI.skins.CheckBox,
  100.  
  101.             left = 710, top = 417,
  102.             
  103.             tabstop = 3,
  104.  
  105.             OnChanged=function(Sender)
  106.                 if (Sender:GetChecked()) then
  107.                     Input:SetInvertedMouse(1);
  108.                 else
  109.                     Input:SetInvertedMouse(0);
  110.                 end
  111.             end,
  112.         },
  113.     
  114.         controllist=
  115.         {
  116.             skin = UI.skins.ListView,
  117.  
  118.             left = 200, top = 140,
  119.             width = 580, height = 259,
  120.             color = "0 0 0 96",
  121.             
  122.             nosort = 1,
  123.             
  124.             tabstop = 1,
  125.  
  126.             vscrollbar=
  127.             {
  128.                 skin = UI.skins.VScrollBar,
  129.             },
  130.  
  131.             hscrollbar=
  132.             {
  133.                 skin = UI.skins.HScrollBar,
  134.             }
  135.         },
  136.         
  137.         reset=
  138.         {
  139.             skin = UI.skins.BottomMenuButton,
  140.             left = 780-180-178.5,
  141.             
  142.             tabstop = 4,
  143.  
  144.             text=Localize("RestoreDefaults"),
  145.  
  146.             OnCommand=function(Sender)
  147.             
  148.                 Input:ResetToDefaults();
  149.                 
  150.                 UI.PageOptionsControl.GUI.invertmouse:SetChecked(0);
  151.                 UI.PageOptionsControl.GUI.sensitivity:SetValue(0.35);
  152.                 
  153.                 UI.PageOptionsControl.GUI.sensitivity:OnChanged(UI.PageOptionsControl.GUI.sensitivity);
  154.                 UI.PageOptionsControl.GUI.invertmouse:OnChanged(UI.PageOptionsControl.GUI.invertmouse);
  155.  
  156.                 UI.PageOptionsControl.FillBindList();
  157.             end,
  158.         },
  159.  
  160.         change=
  161.         {
  162.             skin = UI.skins.BottomMenuButton,
  163.             left = 780-180,
  164.             
  165.             tabstop = 5,
  166.             
  167.             text=Localize("ChangeCtrlBind"),
  168.             
  169.             OnCommand=function(Sender)
  170.                 if UI.PageOptionsControl.GUI.controllist:GetSelectionCount()==1 then -- something selected ???
  171.                     local index=UI.PageOptionsControl.GUI.controllist:GetSelection(0);
  172.                     local Action=UI.PageOptionsControl.Actions[index];
  173.                     if (Action.configurable) then
  174.                         UI.PageWaitForKey:SetLabel(Action);
  175.                         UI:ActivateScreen("BindWaitForKey");
  176.                     end
  177.                 end
  178.             end,
  179.         },
  180.             
  181.         OnActivate= function(Sender)            
  182.             local inv=0;
  183.             if Input:GetInvertedMouse() then
  184.                 inv=1;
  185.             end
  186.             
  187.             -- invert mouse
  188.             UI.PageOptionsControl.GUI.invertmouse:SetChecked(inv);
  189.  
  190.             -- controls
  191.             UI.PageOptionsControl.GUI.controllist:ClearColumns();
  192.             UI.PageOptionsControl.GUI.controllist:Clear();
  193.             UI.PageOptionsControl.GUI.controllist.OnCommand=UI.PageOptionsControl.GUI.change.OnCommand;
  194.  
  195.             UI.PageOptionsControl.GUI.controllist:AddColumn(Localize("CtrlActionName"), 270, UIALIGN_RIGHT, UI.szListViewOddColor, "0 0 0 0");
  196.             UI.PageOptionsControl.GUI.controllist:AddColumn(Localize("CtrlActionBinding1"), 144, UIALIGN_CENTER, UI.szListViewEvenColor, "0 0 0 12");
  197.             UI.PageOptionsControl.GUI.controllist:AddColumn(Localize("CtrlActionBinding2"), 144, UIALIGN_CENTER, UI.szListViewOddColor, "0 0 0 0");
  198.  
  199.             UI.PageOptionsControl.FillBindList();
  200.  
  201.             -- sensitivity
  202.             UI.PageOptionsControl.GUI.sensitivity:SetValue((Input:GetMouseSensitivity()-5.0)/50.0);
  203.  
  204. --    ControlSettingsPage.WarningText=self:CreateStatic(150, 570, 650, 20, 0, "");
  205.             
  206.         end,
  207.     },
  208.  
  209.     ------------------------------------------------------------------------
  210.  
  211.     Actions=nil,            -- 
  212. }
  213.  
  214. function UI.PageOptionsControl:AddBind(Action)
  215.     if ((not Action) or (not Action.actionmaps[1])) then
  216.         return nil
  217.     end
  218.     
  219.     local Binding = Input:GetBinding(Action.actionmaps[1], Action.id);
  220.     local b1="";
  221.     local b2="";
  222.     
  223.     if (Binding[1]) then
  224.         if (Binding[1].mod) then
  225.             b1=Binding[1].mod.." + "..Binding[1].key;
  226.         else
  227.             b1=Binding[1].key;
  228.         end
  229.     end
  230.     
  231.     if (Binding[2]) then
  232.         if (Binding[2].mod) then
  233.             b2=Binding[2].mod.." + "..Binding[2].key;
  234.         else
  235.             b2=Binding[2].key;
  236.         end
  237.     end
  238.     
  239.     return UI.PageOptionsControl.GUI.controllist:AddItem(Action.desc, b1, b2);
  240. end
  241.  
  242. -------------------------------------------------------------------------
  243. function UI.PageOptionsControl.FillBindList()
  244.     
  245.     UI.PageOptionsControl.GUI.controllist:Clear();
  246.     UI.PageOptionsControl.Actions={};
  247.  
  248.     local ActionList = Game:GetActions();
  249.     local ActionMap = {};
  250.  
  251.     for i, Action in ActionList do
  252.         if (Action.configurable and Action.configurable ~= 0) then
  253.             if (not ActionMap[Action.type]) then
  254.                 ActionMap[Action.type] = {};
  255.             end
  256.  
  257.             tinsert(ActionMap[Action.type], Action);
  258.             ActionMap[Action.type].n = nil;
  259.         end
  260.     end
  261.  
  262.     for szType, Map in ActionMap do
  263.     
  264.         local szTypeTitle = "["..strupper(szType).."]";
  265.         local MapOrder = UI.PageOptionsControl.KeyOrder[strupper(szType)];
  266.         
  267.         UI.PageOptionsControl.GUI.controllist:AddItem("$$8"..szTypeTitle.."$1$");
  268.     
  269.         for i, szActionName in MapOrder do
  270.             for j, Action in Map do
  271.                         
  272.                 -- find the key in the list of keys with this szType
  273.                 if (strlower(strsub(Action.desc, 2)) == strlower(szActionName)) or
  274.                     (strlower(strsub(Action.desc, 1)) == strlower(szActionName)) then
  275.                     local iIndex = UI.PageOptionsControl:AddBind(Action);
  276.     
  277.                     if (iIndex) then
  278.                         UI.PageOptionsControl.Actions[iIndex] = Action;    
  279.                         break;
  280.                     end
  281.                 end
  282.             end            
  283.         end
  284.     end
  285. end
  286.  
  287. UI:CreateScreenFromTable("ControlOptions",UI.PageOptionsControl.GUI);